package logic

import (
	"baidu/modil/mysql"
	"context"
	"fmt"
	"strings"

	"baidu/baidurpc/baidurpc"
	"baidu/baidurpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookSellLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBookSellLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookSellLogic {
	return &BookSellLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BookSellLogic) BookSell(in *baidurpc.BookSellRequest) (*baidurpc.BookSellResponse, error) {
	// todo: add your logic here and delete this line
	if strings.Contains(in.Text, "草") || strings.Contains(in.Text, "妈") {
		return nil, fmt.Errorf("您输入你的内容含有铭感词,禁止发言")
	}
	sell := mysql.Sell{
		BookId: int(in.BookId),
		Text:   in.Text,
	}
	mysql.DB.Debug().Create(&sell)
	return &baidurpc.BookSellResponse{
		SellId: int64(sell.ID),
	}, nil
}
